import { CaseSchema, PartySchema } from "@src/components/schema/caseSchema"
import CaseNoRender from '@src/components/caseNoRender'
import moment from 'moment'
import style from '@src/pages/admin/pages/caseManage.module.less'
import { normalStatusList } from '@js/config'
import { Dispatch } from "redux"
import { ColumnType } from 'antd/lib/table';
import { addWindow } from "@src/redux/actions/tab"

 // 获取表格字段配置
 export function getColumns (status: string, dispatch: Dispatch): Array<ColumnType<CaseSchema>> {
  const list: Array<ColumnType<CaseSchema>> = [
    {
      title: '序号',
      dataIndex: 'key',
      key: 'index',
      align: 'center',
      width: 60
    },
    {
      title: '案号',
      dataIndex: 'caseno_desc',
      key: 'caseno_desc',
      render: (v: string, l: CaseSchema) => {
        return <CaseNoRender data={l} />
      }
    },
    {
      title: '申请人',
      dataIndex: 'applicants',
      key: 'applicants',
      width: '15%',
      render: (v: PartySchema[]) => {
        return (v || []).filter(li => li.status).map(li => li.name).join('、')
      }
    },
    {
      title: '被申请人',
      dataIndex: 'respondents',
      key: 'respondents',
      width: '15%',
      render: (v: PartySchema[]) => {
        return (v || []).filter(li => li.status).map(li => li.name).join('、')
      }
    },
    {
      title: '案由',
      dataIndex: 'cause_action',
      key: 'cause_action'
    },
    {
      title: '争议金额',
      dataIndex: 'dispute_amount',
      key: 'dispute_amount',
      render: (v: number) => {
        return String(v || 0).replace(/\B(?=(\d{3})+(?!\d))/g, ',')
      }
    },
    {
      title: '仲裁费',
      dataIndex: 'fee',
      key: 'fee',
      render: (v: number) => {
        return String(v || 0).replace(/\B(?=(\d{3})+(?!\d))/g, ',')
      }
    },
    {
      title: '办案秘书',
      dataIndex: 'processer',
      key: 'processer',
      width: 88
    },
    {
      title: '立案时间',
      dataIndex: 'docket_datetime',
      key: 'docket_datetime',
      width: 120,
      render: (v: number) => {
        return v ? moment(v * 1000).format('YYYY-MM-DD') : ''
      }
    },
    // {
    //   title: '操作',
    //   dataIndex: 'index',
    //   key: 'operate',
    //   render: (value: number, line: CaseSchema) => {
    //     const clickHandle = () => { dispatch(addWindow({ id: `CaseDetail-${line.id}`, title: `案件详情-${line.caseno_desc || '无'}`, componentName: 'CaseDetail', forceRefresh: false, meta: { id: line.id, editable: false } })) }
    //     if (line.cause_action) {
    //       return (<span className={style['operate-btn']} onClick={clickHandle}>详情</span>)
    //     }
    //     return (
    //       <span className={style['operate-cell']}>
    //         <span onClick={clickHandle}>详情</span>
    //         {/* <span onClick={() => this.fullInfo(line)}>完善信息</span> */}
    //       </span>
    //     )
    //   }
    // }
  ]
  if (status && normalStatusList.indexOf(status) !== -1) {
    list.splice(9, 1, {
      title: '立案时间',
      dataIndex: 'docket_datetime',
      key: 'docket_datetime',
      width: 120,
      render: (v: number) => {
        return v ? moment(v * 1000).format('YYYY-MM-DD') : ''
      }
    })
  }
  return list
}